    package com.edu.bhu.admin.controller.admin;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.edu.bhu.common.annotation.Log;
import com.edu.bhu.common.enums.BusinessType;
import com.edu.bhu.admin.domain.CosOrderDetail;
import com.edu.bhu.admin.service.ICosOrderDetailService;
import com.edu.bhu.common.core.controller.BaseController;
import com.edu.bhu.common.core.domain.AjaxResult;
import com.edu.bhu.common.utils.poi.ExcelUtil;
import com.edu.bhu.common.core.page.TableDataInfo;

/**
 * 订单明细Controller
 * 
 * @author wangjinao
 * @date 2022-03-17
 */
@Controller
@RequestMapping("/admin/orderDetail")
public class CosOrderDetailController extends BaseController
{
    private String prefix = "admin/detail";

    @Autowired
    private ICosOrderDetailService cosOrderDetailService;

    @RequiresPermissions("admin:detail:view")
    @GetMapping()
    public String detail()
    {
        return prefix + "/detail";
    }

    /**
     * 查询订单明细列表
     */
    @RequiresPermissions("admin:detail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CosOrderDetail cosOrderDetail)
    {
        startPage();
        List<CosOrderDetail> list = cosOrderDetailService.selectCosOrderDetailList(cosOrderDetail);
        return getDataTable(list);
    }

    /**
     * 导出订单明细列表
     */
    @RequiresPermissions("admin:detail:export")
    @Log(title = "订单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CosOrderDetail cosOrderDetail)
    {
        List<CosOrderDetail> list = cosOrderDetailService.selectCosOrderDetailList(cosOrderDetail);
        ExcelUtil<CosOrderDetail> util = new ExcelUtil<CosOrderDetail>(CosOrderDetail.class);
        return util.exportExcel(list, "订单明细数据");
    }

    /**
     * 新增订单明细
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存订单明细
     */
    @RequiresPermissions("admin:detail:add")
    @Log(title = "订单明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CosOrderDetail cosOrderDetail)
    {
        return toAjax(cosOrderDetailService.insertCosOrderDetail(cosOrderDetail));
    }

    /**
     * 修改订单明细
     */
    @RequiresPermissions("admin:detail:edit")
    @GetMapping("/edit/{orderDetailId}")
    public String edit(@PathVariable("orderDetailId") Long orderDetailId, ModelMap mmap)
    {
        CosOrderDetail cosOrderDetail = cosOrderDetailService.selectCosOrderDetailByOrderDetailId(orderDetailId);
        mmap.put("cosOrderDetail", cosOrderDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存订单明细
     */
    @RequiresPermissions("admin:detail:edit")
    @Log(title = "订单明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CosOrderDetail cosOrderDetail)
    {
        return toAjax(cosOrderDetailService.updateCosOrderDetail(cosOrderDetail));
    }

    /**
     * 删除订单明细
     */
    @RequiresPermissions("admin:detail:remove")
    @Log(title = "订单明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cosOrderDetailService.deleteCosOrderDetailByOrderDetailIds(ids));
    }
}
